package com.huika.renrench.control.my.activity;

import android.content.Intent;
import android.text.TextUtils;
import android.widget.TextView;

import com.android.volley.Response.Listener;
import com.android.volley.VolleyError;
import com.google.gson.reflect.TypeToken;
import com.huika.lib.utils.MoneyShowTool;
import com.huika.renrench.GlobalApp;
import com.huika.renrench.R;
import com.huika.renrench.config.UrlConstants;
import com.huika.renrench.control.common.base.BaseAct;
import com.huika.renrench.http.FormResultRequest;
import com.huika.renrench.http.JSONWrapAjaxParams;
import com.huika.renrench.http.RequestResult;
import com.huika.renrench.support.bean.InvestmentProjectDetailBean;
import com.huika.renrench.view.TitleBarHelper;

/**
 * @author wuwenfeng
 * @date：2015年10月22,下午2:15:30
 * @describe:我投递的项目详情activity
 */
public class InvestmentProjectDetailActivity extends BaseAct implements
		Listener<RequestResult<InvestmentProjectDetailBean>> {
	public static final String PROJECT_ID = "project_id";

	private String projectId;
	
	private InvestmentProjectDetailBean mProjectDetail;

	/**项目名称**/
	private TextView mTvName;
	/**项目描述**/
	private TextView mTvDescription;
	/**所在地**/
	private TextView mTvLocation;
	/**行业分类 **/
	private TextView mTvCategory;
	/**项目关键字**/
	private TextView mTvKeywords;
	/**前期资本预算**/
	private TextView mTvBudget;
	/**手机号 **/
	private TextView mTvMobile;
	/**邮箱**/
	private TextView mTvEmail;
	/**团队介绍**/
	private TextView mTvTeamDesc;
	/**核心竞争力**/
	private TextView mTvCoreCompetence;
	
	@Override
	protected void initData() {
		// TODO Auto-generated method stub
		super.initData();
		Intent intent = getIntent();
		if(intent != null){
			projectId = (String) intent.getExtras().get("projectId");
		}
		
	}


	@Override
	public void setRootView() {
		setContentView(R.layout.activity_investment_project_detail);
	}
	
	@Override
	protected void initWidget() {
		super.initWidget();
		
		new TitleBarHelper(this, R.string.left_back, -1, R.string.title_activity_project_detail);
		
		mTvName = (TextView) findViewById(R.id.tv_project_name);
		mTvDescription = (TextView) findViewById(R.id.tv_project_description);
		mTvLocation = (TextView) findViewById(R.id.tv_project_location);
		mTvCategory = (TextView) findViewById(R.id.tv_project_category);
		mTvKeywords = (TextView) findViewById(R.id.tv_project_keywords);
		mTvBudget = (TextView) findViewById(R.id.tv_project_budget);
		mTvMobile = (TextView) findViewById(R.id.tv_project_mobile);
		mTvEmail = (TextView) findViewById(R.id.tv_project_email);
		mTvTeamDesc = (TextView) findViewById(R.id.tv_project_team_desc);
		mTvCoreCompetence = (TextView) findViewById(R.id.tv_project_coreCompetence);
		
		/** 获取网络数据 **/
		getNetData();

	}

	private String getUserId() {
		String u_id = GlobalApp.getInstance().getUserId();
		return TextUtils.isEmpty(u_id) ? "0" : u_id;  
	}

	private void getNetData() {
		showLoadingDialog(getString(R.string.common_loading));
		JSONWrapAjaxParams ajaxParams = new JSONWrapAjaxParams();
		ajaxParams.putCommonTypeParam("pid", projectId);
		ajaxParams.putCommonTypeParam("userId", getUserId());
		
		FormResultRequest<InvestmentProjectDetailBean> getResultRequest = new FormResultRequest<InvestmentProjectDetailBean>(
				UrlConstants.INVESTMENT_PROJECT_DETAIL, this, this,
				new TypeToken<RequestResult<InvestmentProjectDetailBean>>() {
				}.getType());
		
		getResultRequest.setRequestParams(ajaxParams);
		executeRequest(getResultRequest);

	}

	@Override
	public void onResponse(RequestResult<InvestmentProjectDetailBean> result) {
		dismissLoadingDialog();
		if (result.flag == 1) {
			if (result.getRs() != null) {
				mProjectDetail = result.getRs();
			    
				refreshUI();
			}
		}

	}

	private void refreshUI() {
		mTvName.setText(mProjectDetail.getName());
		mTvDescription.setText(mProjectDetail.getDescription());
		mTvLocation.setText(mProjectDetail.getLocation());
		mTvCategory.setText(mProjectDetail.getIndustryCategory());
		mTvKeywords.setText(mProjectDetail.getKeywords());
		mTvBudget.setText(MoneyShowTool.twolastDF(mProjectDetail.getBudget()) + "万元");
		mTvMobile.setText(mProjectDetail.getMobile());
		mTvEmail.setText(mProjectDetail.getEmail());
		mTvTeamDesc.setText(mProjectDetail.getTeamDesc());
		mTvCoreCompetence.setText(mProjectDetail.getCoreCompetence());
	}


	@Override
	public void onErrorResponse(VolleyError error) {
		super.onErrorResponse(error);
	}

}
